

def jwt_response_payload_handler(token, user=None, request=None):
    """
    自定义jwt认证成功返回数据
    """
    return {
        'token': token,
        'id': user.id,
        'username': user.username
    }


from users import models
from django.db.models import Q
def get_user_obj(account):
    try:
        user_obj = models.User.objects.get(Q(username=account)|Q(phone=account))
    except:
        return None
    return user_obj


from django.contrib.auth.backends import ModelBackend

class CustomModelBackend(ModelBackend):

    def authenticate(self, request, username=None, password=None, **kwargs):
        user_obj = get_user_obj(username)
        if user_obj:
            if user_obj.check_password(password):
                return user_obj
        else:
            return None

# class CustomModelBackend(ModelBackend):
#
#     user_obj = get_user_obj(self.username)
#     def authenticate(self, request, username=None, password=None, **kwargs):
#         if user_obj and user_obj.check_password(password):
#             return None











